package com.xjwlmq.dx.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName DemoServlet
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/10 23:27
 * @Version 1.0
 **/
@WebServlet("/demoServlet")
public class DemoServlet extends HttpServlet {
    /*
     * Tomcat服务器会在[启动服务器或客户机首次访问时]执行Servlet实例化(构造方法)与资源初始化(init)
     * 在每次请求时通过service方法处理请求(可以智能判断get/post(等效doGet+doPost, 但会重载掉它们))
     * 在Tomcat服务器停止时 或者触发GC时 通过destroy方法销毁实例
     */
    public DemoServlet() {
        System.out.println("Instanced.");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("initiated.");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Do DemoServlet.");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Get.");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Post.");
    }

    @Override
    public void destroy() {
        System.out.println("Destroyed.");
    }
}
